package io.renren.modules.app.config;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.renren.modules.app.entity.VehicleEntity;
import io.renren.modules.app.utils.HttpUtils;
import io.renren.modules.app.utils.TencentSign;
import org.apache.http.HttpResponse;
import org.apache.http.util.EntityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * @Auther zxl
 * @Date 2019/1/9 13:07
 * @Description
 **/
@ConfigurationProperties(prefix = "tencent.ocr")
@Component
public class TencentOCRConfig {

    private Logger logger = LoggerFactory.getLogger(getClass());

    private String host;
    private String appId;
    private String secretId;
    private String secretKey;

//    /**
//     * 行驶证识别
//     * @param base64
//     * @return
//     */
//    public void ocr(String base64) throws Exception {
//
//        //  请求头
//        Map<String, String> headers = new HashMap<>(10);
//        String authorization = TencentSign.appSign(Long.parseLong(this.getAppId()),
//                                this.getSecretId(),this.getSecretKey(),"吉速车福",60);
//        System.out.println("host:"+this.getHost());
//        headers.put("Host",this.getHost());
////        headers.put("User-Agent","Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 1.7; .NET CLR 1.1.4322; CIBA; .NET CLR 2.0.50727)");
//        headers.put("Content-Type","application/json");
//        headers.put("Content-Length","187");
//        headers.put("Authorization", authorization);
//        // 拼装请求body的json字符串
//        Map<String,String> content = new HashMap<>(5);
//        content.put("appid",this.getAppId());
//        content.put("bucket","吉速车福");
////        识别类型，0 表示行驶证，1 表示驾驶证，2 表示行驶证副页。
//        content.put("type","0");
//        content.put("image",base64);
//
////        JSONObject requestObj = new JSONObject();
////        requestObj.put("appid",this.getAppId());
////        requestObj.put("bucket","吉速车福");
//////
////        requestObj.put("type","0");
////        requestObj.put("image",base64);
//
//        logger.info("腾讯云，行驶证解析请求发送。。。。"+System.currentTimeMillis());
//        String url = "http    ://recognition.image.myqcloud.com/ocr/drivinglicence";
//        String res = HttpUtils.postMap(url,headers,content);
//        logger.info("腾讯云，行驶证解析请求完成。。。。"+System.currentTimeMillis());
//        if(res == null){
//            System.out.println("失败");
//        }else{
//            JSONObject res_obj = JSON.parseObject(res);
//            System.out.println(res_obj.toJSONString());
//        }
//    }

    public String getAppId() {
        return appId;
    }

    public void setAppId(String appId) {
        this.appId = appId;
    }

    public String getSecretId() {
        return secretId;
    }

    public void setSecretId(String secretId) {
        this.secretId = secretId;
    }

    public String getSecretKey() {
        return secretKey;
    }

    public void setSecretKey(String secretKey) {
        this.secretKey = secretKey;
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }
}
